const { DataTypes } = require("sequelize");

const seq = require("../db/seq");

const Question = seq.define(
  "question",
  {
    id: {
      type: DataTypes.UUID,
      allowNull: false,
      defaultValue: DataTypes.UUIDV4, // 或 DataTypes.UUIDV1
      primaryKey: true,
      comment: "id，主键，uuid格式",
    },
    createdId: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "创建的用户id",
    },
    title: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "默认问卷标题",
      comment: "问卷标题",
    },
    isPrompt: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 0,
      comment: "是否提示；0否（默认）、1是",
    },
    desc: {
      type: DataTypes.STRING,
      comment: "问卷描述",
    },
    is_published: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 0,
      comment: "是否已发布；0否（默认）、1是",
    },
    is_star: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 0,
      comment: "是否已标星；0否（默认）、1是",
    },
    is_deleted: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 0,
      comment: "是否已删除；0否（默认）、1是",
    },
  },
  {
    timestamps: true,
    createdAt: "createdAt",
    updatedAt: "updatedAt",
  }
);

// 初始化模型
async function initModel() {
  await Question.sync({ alter: true });
}

// initModel();

module.exports = Question;
